package com.wbt.bambootown.ui.adapter;


import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wbt.bambootown.R;
import com.wbt.bambootown.entity.CameraPic;
import com.wbt.bambootown.entity.DevicesData;
import com.wbt.bambootown.ui.view.recyclerview.BaseAdapter;
import com.wbt.bambootown.ui.view.recyclerview.BaseViewHolder;
import com.zhy.autolayout.utils.AutoUtils;


/**
 * Created by wufan on 2018/5/16.
 */

public class DevicesDataAdapter extends BaseAdapter<DevicesData, BaseViewHolder>{

    private Context context;

    public DevicesDataAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public BaseViewHolder createCustomViewHolder(ViewGroup parent, int viewType) {
        return new BaseViewHolder(parent , R.layout.item_devices_data);
    }

    @Override
    public void bindCustomViewHolder(final BaseViewHolder viewHolder, final int position) {
        AutoUtils.autoSize(viewHolder.itemView);

        final DevicesData item = getItem(position);
        TextView mTvName = viewHolder.getTextView(R.id.tv_name);
        TextView mTvTime = viewHolder.getTextView(R.id.tv_time);
        TextView mTvValue = viewHolder.getTextView(R.id.tv_value);
        TextView mTvUnit = viewHolder.getTextView(R.id.tv_unit);
        ImageView mIvQuery = viewHolder.getImageView(R.id.iv_query);

        Drawable drawable = null;
        switch (item.getId()){
            case 1:
                drawable= context.getResources().getDrawable(R.drawable.ammonia);
                break;
            case 2:
                drawable= context.getResources().getDrawable(R.drawable.humidity);
                break;
            case 3:
                drawable= context.getResources().getDrawable(R.drawable.temperature);
                break;
            case 4:
                drawable= context.getResources().getDrawable(R.drawable.illumination);
                break;
            case 5:
                drawable= context.getResources().getDrawable(R.drawable.sulfide);
                break;
            case 6:
                drawable= context.getResources().getDrawable(R.drawable.carbon);
                break;
            default:
                break;
        }

        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        mTvName.setCompoundDrawables(drawable,null,null,null);

        mTvName.setText(item.getName());
        mTvTime.setText(item.getTime());
        mTvValue.setText(item.getValue());
        mTvUnit.setText("单位(" + item.getUnit() + ")");

        mIvQuery.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnItemClick.query(item.getId() , item.getName());
            }
        });
    }

    @Override
    public int getCustomViewType(int position) {
        return 0;
    }


    public onItemClick mOnItemClick;

    public interface onItemClick {
        public void query(int id , String name);
    }

    public void setListener(onItemClick mListener) {
        this.mOnItemClick = mListener;
    }
}
